import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router);
let routeArr = [
    {name: 'home', path:'home/index',meta:{title:'互助筹',showH:false,showF:true,noBack:false,tabIndex:0}},
    {name: 'detail', path:'home/detail',meta:{title:'众筹详情'}},
    {name: 'help', path:'home/help',meta:{title:'发起帮助'}},
    {name: 'login', path:'login/index',meta:{title:'登录',showH:false}},
    {name: 'register', path:'login/register',meta:{title:'注册',showH:false}},
    {name: 'self', path:'self/index',meta:{title:'我的',showH:false,showF:true,tabIndex:2}},
    {name: 'setting', path:'self/setting',meta:{title:'设置'}},
    {name: 'give', path:'self/give',meta:{title:'我的捐献'}},
    {name: 'publish', path:'self/publish',meta:{title:'我的发布'}},
    {name: 'treams', path:'self/treams',meta:{title:'我的团队'}},
    {name: 'sendCode', path:'self/sendCode',meta:{title:''}},
    {name: 'modifyTel', path:'self/modifyTel',meta:{title:''}},
    {name: 'score', path:'self/score',meta:{title:'我的积分',showH:false}},
    {name: 'bindAccount', path:'self/bindAccount',meta:{title:'绑定账户'}},
    {name: 'scoreIn', path:'self/scoreIn',meta:{title:'积分充值'}},
    {name: 'scoreInNext', path:'self/scoreInNext',meta:{title:'积分充值'}},
    {name: 'scoreOut', path:'self/scoreOut',meta:{title:'积分提现'}},
    {name: 'scoreRecord', path:'self/scoreRecord',meta:{title:'积分记录'}},
    {name: 'invite', path:'self/invite',meta:{title:'我的邀请',showH:false}},
    {name: 'poster', path:'self/poster',meta:{title:'分享海报'}},
    {name: 'heart', path:'self/heart',meta:{title:'分享海报',showH:false}},
    {name: 'publish1', path:'publish',meta:{title:'发起筹款'}},
    {name: 'vipScore', path:'self/vipScore',meta:{title:'会员充值'}},
]
const routes = [];
routeArr.forEach((val,index,arr) => {
    //判断meta中是否存在showH属性
    if(!val.meta.hasOwnProperty("showH")){
        val.meta.showH = true
    }
    if(!val.meta.hasOwnProperty("noBack")){
        val.meta.noBack = true
    }
    let route = {
        path:val.name == 'home' ? '/' :'/'+
            val.name ,//网站默认页
        name:val.name,
        component: () => import('@/pages/'+val.path),
        meta:val.meta
    };
    routes.push(route)
});
console.log(routes);
const router = new Router({
    routes:routes
});
router.beforeEach((to,from,next)=>{
    document.title = to.meta.title;
    next();
    // if(localStorage.getItem('token')){
    //
    // }else{
    //     if(to.name == "login" || to.name== 'register'){
    //         next()
    //     }else{
    //         next({
    //             path:"/login"
    //         })
    //     }
    // }

});
export default router
